/*
 * @lc app=leetcode.cn id=704 lang=javascript
 *
 * [704] 二分查找
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function(nums, target) {
    if (nums.length == 0) return -1
    let i = 0, j = nums.length - 1
    while (i <= j) {
        let mid = Math.floor((i + j) / 2)
        if (nums[mid] > target) {
            j = mid - 1
        }
        else if (nums[mid] < target) {
            i = mid + 1
        }
        else {
            return mid
        }
    }
    return -1
};
// @lc code=end

function test(n, v, a) {
    if (n == 0) return 1
    let i = 0, j = n-1, index = n + 1
    while (i <= j) {
        let mid = Math.floor((i + j) / 2)
        if (a[mid] >= v) {
            j = mid - 1
            index = mid + 1
        }
        else {
            i = mid + 1
        }
    }
    return index
}
let ans = test(100,100,[2,3,3,4,4,5,5,5,6,6,7,7,9,9,9,10,10,12,14,16,17,18,18,18,19,22,23,23,26,26,26,26,28,28,29,29,29,32,33,35,36,38,39,39,40,41,46,47,47,47,49,50,54,55,55,55,56,57,57,58,58,58,59,61,61,62,62,62,62,63,63,67,67,69,70,70,71,72,74,75,76,79,84,85,85,86,89,92,93,93,93,94,94,95,97,97,97,97,97,99])
console.log(ans)